package com.guxingke.gblog.controller.front;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.guxingke.gblog.controller.BaseController;

@Controller
@RequestMapping("/article")
public class ArticleController extends BaseController {
	
	@RequestMapping("/archive")
	public ModelAndView list() {
		ModelAndView mav = new ModelAndView();
		mav.addObject("archives", articleService.getArchive());
		mav.addObject("mainPage", "archive/detail.jsp");
		mav.setViewName("home");
		return mav;
	}
	
	@RequestMapping("/detail")
	public ModelAndView get(@RequestParam(value="articleId",required=true) Integer id) {
		ModelAndView mav = new ModelAndView();
		
		mav.addObject("pid",id);
		mav.addObject("type", 0);
		mav.addObject("replytype", 2);
		mav.addObject("msgs",msgService.getComments(id));
		mav.addObject("preArticle",articleService.getPreArticle(id));
		mav.addObject("nextArticle",articleService.getNextArticle(id));
		mav.addObject("article",articleService.getArticle(id));
		mav.addObject("mainPage", "article/detail.jsp");
		mav.setViewName("home");
		return mav;
	}
	
	@RequestMapping("/about")
	public ModelAndView about() {
		ModelAndView mav = new ModelAndView();
		mav.addObject("about",articleService.getAbout());
		mav.addObject("mainPage", "about/detail.jsp");
		mav.setViewName("home");
		return mav;
	}
}
